package com.pz.chat.exception;

import com.pz.gulimall.common.exception.BizCodeEnum;
import com.pz.gulimall.common.exception.RRException;
import com.pz.gulimall.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MultipartException;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 集中处理所有的异常，配合数据校验优化代码
 */
@Slf4j
@RestControllerAdvice(basePackages = "com.pz.chat.netty_ws")
public class NettyGlobalHandlerAdvice {

    //处理所有的异常
    @ExceptionHandler(value = Throwable.class)
    public R handleAllException(Throwable throwable){
        log.error("有未知异常-->{}", throwable.getMessage());
        return R.error(throwable.getMessage());
    }

    @ExceptionHandler(value = RRException.class)
    public R handleOwnException(RRException throwable){
        log.error(throwable.getMessage());
        return R.error(throwable.getCode(), throwable.getMsg());
    }
}
